package com.logic.landseaserver.common.enums;

import org.apache.commons.lang.StringUtils;

public enum PaymentModelCodeEnum {
    // code 付X  押Y 付款方式
    //付一押一
    PAMO8("PAMO8", 1, 1,1),
    //付一押二
    PAMO1("PAMO1", 1, 2,1),
    //付三押二
    PAMO3("PAMO3", 3, 2,2),
    //付三押一
    PAMO5("PAMO5", 3, 1 ,2),
    //付六押一
    PAMO6("PAMO6", 6, 1,3),
    //全额付清
    PAMO7("PAMO7", 0, 1 ,5),
    //付六押二
    PAMO9("PAMO9", 6, 2,3);

    PaymentModelCodeEnum(String code, Integer payMonth, Integer depositMonth,Integer payment) {
        this.code = code;
        this.payMonth = payMonth;
        this.depositMonth = depositMonth;
        this.payment = payment;
    }

    private String code;
    private Integer payMonth;
    private Integer depositMonth;
    private Integer payment;

    public Integer getPayMonth() {
        return payMonth;
    }

    public void setPayMonth(Integer payMonth) {
        this.payMonth = payMonth;
    }

    public Integer getDepositMonth() {
        return depositMonth;
    }

    public void setDepositMonth(Integer depositMonth) {
        this.depositMonth = depositMonth;
    }

    private PaymentModelCodeEnum(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getPayment() {
        return payment;
    }

    public void setPayment(Integer payment) {
        this.payment = payment;
    }

    public static Integer getDepositMonth(String code) {

        PaymentModelCodeEnum[] vals = PaymentModelCodeEnum.values();

        for (PaymentModelCodeEnum paymentModelCodeEnum : vals) {

            if (paymentModelCodeEnum.code.equals(code)) {

                return paymentModelCodeEnum.getDepositMonth();
            }
        }
        return null;
    }

    public static PaymentModelCodeEnum getPaymentModelCodeEnum(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        for (PaymentModelCodeEnum paymentModelCodeEnum : PaymentModelCodeEnum.values()) {
            if (paymentModelCodeEnum.code.equals(code)) {
                return paymentModelCodeEnum;
            }
        }
        return null;
    }

    public static Integer setPaymentModelCode(Integer leaseM ,String code) {
        if (leaseM == null ){
            return null;
        }
        PaymentModelCodeEnum resultEnum = getPaymentModelCodeEnum(code);

        if(resultEnum != null){
            if(leaseM < resultEnum.getPayMonth()){
                return  5;
            }
        }
        return resultEnum.getPayment();
    }
}
